;; 全局键盘绑定
;; 载入redo操作
(require 'redo+)
;; 载入功能键绑定
(load "refcard")

;; 习惯设置，Home键设定光标到文件开头
(global-set-key [(home)] 'beginning-of-buffer)
;; 习惯设置，End键设定光标到文件结尾
(global-set-key [(end)] 'end-of-buffer)


;; Meta
;; tabbar按键设置
(global-set-key [(meta \[)] 'tabbar-backward)
(global-set-key [(meta \])] 'tabbar-forward)
;; 绑定花括号匹配函数
(global-set-key [(meta left)] 'backward-sexp)
(global-set-key [(meta right)] 'forward-sexp)
;; 定义goto-line快捷键
(global-set-key [(meta g)] 'goto-line)
;; 正则替换
(global-set-key [(meta r)] 'replace-regexp)
;; 注释
(global-set-key [(meta m)] 'comment-region)
(global-set-key [(meta u)] 'uncomment-region)
;; 绑定王垠的跳转函数
(global-set-key [(control ?.)] 'ska-point-to-register)
(global-set-key [(control ?\,)] 'ska-jump-to-register)

;; 将 C-s 和 C-M-s的意义调换
(global-set-key [(control s)] 'isearch-forward-regexp)
(global-set-key [(control meta s)] 'isearch-forward)
(global-set-key [(control r)] 'isearch-backward-regexp)
(global-set-key [(control meta r)] 'isearch-backward)

;; 定义跳转到上一窗口函数，来自sam-lib.el
(defun sams-other-window-backwards (arg) ;[Jesper]
  "Like `other-window', but moves in the opposite direction."
  (interactive "p")
  (other-window (- 0 arg)))
;; 设置窗口跳转快捷键
(global-set-key (kbd "C--") 'sams-other-window-backwards)
(global-set-key (kbd "C-=") 'other-window)

;; 設置buffer管理為ibuffer
(global-set-key (kbd "C-x C-b") 'ibuffer)

;; global key-map
;; all global keys prefix is C-c e
;; compatible with emms-playlist mode keybindings
;; you can view emms-playlist-mode.el to get details about
;; emms-playlist mode keys map
(global-set-key (kbd "C-c e s") 'emms-stop)
(global-set-key (kbd "C-c e P") 'emms-pause)
(global-set-key (kbd "C-c e n") 'emms-next)
(global-set-key (kbd "C-c e p") 'emms-previous)
(global-set-key (kbd "C-c e f") 'emms-show)
(global-set-key (kbd "C-c e >") 'emms-seek-forward)
(global-set-key (kbd "C-c e <") 'emms-seek-backward)
;; these keys maps were derivations of above keybindings
(global-set-key (kbd "C-c e S") 'emms-start)
(global-set-key (kbd "C-c e g") 'emms-playlist-mode-go)
(global-set-key (kbd "C-c e t") 'emms-play-directory-tree)
(global-set-key (kbd "C-c e h") 'emms-shuffle)
(global-set-key (kbd "C-c e e") 'emms-play-file)
(global-set-key (kbd "C-c e l") 'emms-play-playlist)
(global-set-key (kbd "C-c e r") 'emms-toggle-repeat-track)
(global-set-key (kbd "C-c e R") 'emms-toggle-repeat-playlist)
(global-set-key (kbd "C-c e u") 'emms-score-up-playing)
(global-set-key (kbd "C-c e d") 'emms-score-down-playing)
(global-set-key (kbd "C-c e o") 'emms-score-show-playing)

(provide 'jerry-key-bindings)
